package com.wfuhui.modules.oms.controller;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.wfuhui.common.utils.Query;
import com.wfuhui.common.utils.R;
import com.wfuhui.modules.oms.entity.BannerEntity;
import com.wfuhui.modules.oms.service.BannerService;

/**
 * Banner
 */
@RestController
@RequestMapping("/oms/banner")
public class BannerController {
	@Autowired
	private BannerService bannerService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("banner:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<BannerEntity> bannerList = bannerService.queryList(query);
		int total = bannerService.queryTotal(query);
		
		return R.ok().put("rows", bannerList).put("total", total);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{bannerId}")
	@RequiresPermissions("banner:info")
	public R info(@PathVariable("bannerId") Integer bannerId){
		BannerEntity banner = bannerService.queryObject(bannerId);
		
		return R.ok().put("banner", banner);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("banner:save")
	public R save(@RequestBody BannerEntity banner){
		banner.setCreateTime(new Date());
		bannerService.save(banner);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("banner:update")
	public R update(@RequestBody BannerEntity banner){
		bannerService.update(banner);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("banner:delete")
	public R delete(@RequestBody Integer[] bannerIds){
		bannerService.deleteBatch(bannerIds);
		
		return R.ok();
	}
	
}
